import { _decorator, Component, Node, Vec3, tween } from 'cc';
const { ccclass, property } = _decorator;
 
@ccclass
export default class Follow extends Component {
 
    @property(Node)
    target: Node = null;
    @property(Vec3)
    offset: Vec3 = new Vec3(0, 0, 0);
 
    update () {
        if (!this.target) {
            return
        }
        const w = this.target.getPosition()
        const { x, y } = w
        let newx = x, newy = y
        if (x > 300) {
            newx = 300
        }
        if (x < -300) {
            newx = -300
        }
        if (y > 460) {
           newy = 460
        }
        if (y < -460) {
            newy = -460
        }
        this.node.setPosition(new Vec3(newx, newy, 0))
    }
}